package com.bcxk.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bcxk.entity.dto.Room;
import com.bcxk.entity.dto.RoomFacility;
import com.bcxk.entity.po.RoomPo;
import com.bcxk.mapper.RoomMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RoomService extends ServiceImpl<RoomMapper, Room> {

    @Resource
    RoomFacilityService facilityService;

    @Transactional(readOnly = true)
    public List<RoomPo> getRoomsByMinSuId(Long minsuId) {
        List<RoomPo> roomPos = this.baseMapper.getRoomsByMinSuId(minsuId);
        for (RoomPo roomPo:roomPos) {
            Long roomId = roomPo.getId();
            List<RoomFacility> facilities = facilityService.getFacilitysByRoomId(roomId);
            roomPo.setRoomFacilities(facilities);
        }
        return roomPos;
    }
}
